/**
 * Created by Administrator on 2017/8/28 0028.
 */
import * as types from '../mutation-types'

const state = {
  // user: {
  //   name: '',
  //   unit: '',
  //   phone: ''
  // }
  clients: []
}

const mutations = {
  [types.USER_LOGIN] (state, res) {
    console.log(res)
    state.clients = []
    for (let i in res.res.body.clients) {
      state.clients.push(JSON.parse(res.res.body.clients[i]))
    }
    localStorage.username = res.res.body.user
    localStorage.token = res.res.body.token
  },
  [types.BIMSERVER_ADDCLIENT] (state, res) {
    state.clients.push(JSON.parse(res.res.body.clients))
  },
  [types.BIMSERVER_DELETECLIENT] (state, options) {
    state.clients.splice(state.clients.findIndex(function (ele, index, array) { return ele.id === options.id }), 1)
  },
  [types.BIMSERVER_UPDATE_CLIENT] (state, options) {
    console.log(state.clients[state.clients.findIndex((ele) => ele.id === options.id)])
    console.log(options)
    for (let i in options) {
      state.clients[state.clients.findIndex((ele) => ele.id === options.id)][i] = options[i]
    }
  }
}
export default {
  state,
  mutations
}
